package com.baitengsoft.patentapimonitor.api.service.impl;

import com.baitengsoft.patentapimonitor.api.dao.PacPatentinfoDao;
import com.baitengsoft.patentapimonitor.api.dao.WebPlatFormAreaDao;
import com.baitengsoft.patentapimonitor.api.dao.WebPlatformDao;
import com.baitengsoft.patentapimonitor.api.entity.PacPatentinfoEntity;
import com.baitengsoft.patentapimonitor.api.entity.WebPlatformEntity;
import com.baitengsoft.patentapimonitor.api.model.*;
import com.baitengsoft.patentapimonitor.api.model.param.SearchExpiryNoticeParam;
import com.baitengsoft.patentapimonitor.api.model.param.SearchMonSummaryParam;
import com.baitengsoft.patentapimonitor.api.model.param.SearchPatentParam;
import com.baitengsoft.patentapimonitor.api.service.CfgDictionaryService;
import com.baitengsoft.patentapimonitor.api.service.PacPatentinfoService;
import com.baitengsoft.patentapimonitor.common.utils.DateUtils;
import com.baitengsoft.patentapimonitor.common.utils.PageResult;
import com.baitengsoft.patentapimonitor.common.utils.Res;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.io.InputStream;
import java.util.*;

/**
 * 平台专利信息实体类实现类
 *
 * @author Chen 2017/12/21
 */
@Service
public class PacPatentinfoServiceImpl extends BaseServiceImpl<PacPatentinfoEntity> implements PacPatentinfoService {
    class CheckResult {
        Boolean isSuccess;
        String errorMessage;

        public CheckResult(String errorMessage) {
            this.isSuccess = false;
            this.errorMessage = errorMessage;
        }

        public CheckResult(Boolean isSuccess) {
            this.isSuccess = isSuccess;
        }

        public Boolean isSuccess() {
            return isSuccess;
        }

        public void setIsSuccess(Boolean success) {
            isSuccess = success;
        }

        public String getErrorMessage() {
            return errorMessage;
        }

        public void setErrorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
        }
    }

    @Autowired
    private PacPatentinfoDao pacPatentinfoDao;
    @Autowired
    private WebPlatFormAreaDao webPlatFormAreaDao;
    @Autowired
    private WebPlatformDao webPlatformDao;
    @Autowired
    private CfgDictionaryService cfgDictionaryService;

    private static final List<Integer> checkColumn = Arrays.asList(0, 1, 2);

    /**
     * 根据平台id和输入流导入Excel
     */
    @Override
    public Res importPatInfoByPlatforomId(Integer platformid, InputStream inputStream) throws Exception {
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inputStream);
        CheckResult checkResult = checkExcelData(hssfWorkbook);
        if (!checkResult.isSuccess)
            return Res.error(checkResult.getErrorMessage());
        HSSFSheet sheet = hssfWorkbook.getSheet("Sheet1");
        HSSFRow row = null;
        int rowNum = sheet.getLastRowNum();
        String notices = "";
        for (int i = 1; i <= rowNum; i++) {
            row = sheet.getRow(i);
            PacPatentinfoEntity entity = new PacPatentinfoEntity();
            HSSFCell cell = row.getCell(0);//申请号
            entity.setPatnum(cell.getStringCellValue());
            cell = row.getCell(1);//申请日
            entity.setPatappdate(cell.getDateCellValue());
            cell = row.getCell(2); //申请人地址
            entity.setPataddress(cell.getStringCellValue());
            Example example = new Example(PacPatentinfoEntity.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("platformid", platformid);
            criteria.andEqualTo("patnum", entity.getPatnum());
            List<PacPatentinfoEntity> entities = pacPatentinfoDao.selectByExample(example);
            if (entities.size() > 0) {
                //不进行导入，友好提示
                notices += ("第" + (i + 1) + "条,");
            } else {
                entity.setIsimport(1);
                entity.setStatus(1);
                entity.setIslock(false);
                entity.setCreatedate(new Date());
                entity.setUpdatedate(new Date());
                entity.setPlatformid(platformid);
                pacPatentinfoDao.insert(entity);
            }
        }
        if (notices.equals("")) {
            return Res.ok("导入成功");
        } else {
            return Res.ok("导入完成！" + notices + "数据库中存在，已跳过。");
        }
    }

    @Override
    public Res saveInportPatInfos(List<PacPatentinfoEntity> entities) {
        for (PacPatentinfoEntity entity : entities) {
            Example example = new Example(PacPatentinfoEntity.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("platformid", entity.getPlatformid());
            criteria.andEqualTo("patnum", entity.getPatnum());
            List<PacPatentinfoEntity> example1 = pacPatentinfoDao.selectByExample(example);
            if (example1 != null && example1.size() > 0) {
                PacPatentinfoEntity entity1 = example1.get(0);
                entity1.setIsimport(1);
                pacPatentinfoDao.updateByPrimaryKey(entity1);
            } else {
                entity.setIsimport(1);
                pacPatentinfoDao.insertSelective(entity);
            }
        }
        return Res.ok();
    }

    @Override
    public PageResult<PacPatentInfo> searchByParam(SearchPatentParam param, Integer platformId) {
        if (param.getPatType() != null && param.getPatType().size() > 0) {
            if (param.getPatType().contains(1)) param.getPatType().add(8);
            if (param.getPatType().contains(2)) param.getPatType().add(9);
        }
        Example example = getExampleByParam(param, platformId);
        Page<Object> page = PageHelper.startPage(param.getPageNumber(), param.getPageSize());
        List<PacPatentinfoEntity> entities = pacPatentinfoDao.selectByExample(example);
        List<PacPatentInfo> infos = new ArrayList<>();
        //专利类型map
        Map<String, String> patTypeMap = cfgDictionaryService.getPatTypeMap();
        //法律状态map
        Map<String, String> lowStatus = cfgDictionaryService.getLowStatus();
        for (PacPatentinfoEntity entity : entities) {
            PacPatentInfo info = new PacPatentInfo();
            info.setPatNum(entity.getPatnum());
            info.setPatName(entity.getPatname());
            info.setPatTypeName(patTypeMap.get(entity.getPattypename().toString()));
            info.setLawState(lowStatus.get(entity.getLawstate().toString()));
            info.setApplyPerson(entity.getApplyperson());
            info.setInventPerson(entity.getInventperson());
            info.setPatAppDate(DateUtils.format(entity.getPatappdate()));
            info.setPublicationDate(DateUtils.format(entity.getPublicationdate()));
            info.setPatSubExamDate(DateUtils.format(entity.getPatsubexamdate()));
            info.setPatApproveDate(DateUtils.format(entity.getPatapprovedate()));
            info.setExpiryDate(DateUtils.format(entity.getExpirydate()));
            info.setPatAddressLast(entity.getPataddresslast());
            info.setAgencyName(entity.getAgencyname());
            infos.add(info);
        }
        Long total = page.getTotal();
        PageResult<PacPatentInfo> r = new PageResult<>(infos, param.getPageNumber(), param.getPageSize(), total.intValue());
        return r;
    }

    @Override
    public Res getMonSummaryinfo(WebPlatformEntity platformEntity) {
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        Integer expiredmonths = platformEntity.getExpiredmonths();//获取平台届满时间，默认为1
        if (expiredmonths == null) expiredmonths = 1;
        //获取发明专利届满数量 申请日+20年
        Integer fmcount = pacPatentinfoDao.getFMExpiredInfo(expiredmonths, platformEntity.getId());
        //获取其他专利届满数量 申请日+10年
        Integer count = pacPatentinfoDao.getExpiredInfo(expiredmonths, platformEntity.getId());
        Map<String, Integer> map = new HashMap<>();
        map.put("months", expiredmonths);
        map.put("count", fmcount + count);
        //获取今年转入数据
        Integer inInfo = pacPatentinfoDao.getInByYear(startDate, endDate, platformEntity.getId());
        //获取今年转出数据
        Integer outInfo = pacPatentinfoDao.getOutByYear(startDate, endDate, platformEntity.getId());
        //获取今年专利失效
        Integer expiryInfo = pacPatentinfoDao.getExpiredYear(startDate, endDate, platformEntity.getId());
        return Res.ok().put("expiration", map).put("yearIn", inInfo).put("yearOut", outInfo).put("yearExpiry", expiryInfo);
    }

    @Override
    public WebMonSummaryExportinfo getMonSummaryExportinfo(WebPlatformEntity platformEntity) {
        WebMonSummaryExportinfo info = new WebMonSummaryExportinfo();
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        Integer expiredmonths = platformEntity.getExpiredmonths();//将来一个月即将届满
        if (expiredmonths == null) expiredmonths = 1;
        Integer fmcount = pacPatentinfoDao.getFMExpiredInfo(expiredmonths, platformEntity.getId());
        Integer count = pacPatentinfoDao.getExpiredInfo(expiredmonths, platformEntity.getId());
        //获取今年转入数据
        Integer inInfo = pacPatentinfoDao.getInByYear(startDate, endDate, platformEntity.getId());
        //获取今年转出数据
        Integer outInfo = pacPatentinfoDao.getOutByYear(startDate, endDate, platformEntity.getId());
        //获取今年专利失效
        Integer expiryInfo = pacPatentinfoDao.getExpiredYear(startDate, endDate, platformEntity.getId());
        info.setCount(fmcount + count);
        info.setMonths(expiredmonths);
        info.setInInfo(inInfo);
        info.setOutInfo(outInfo);
        info.setExpiryInfo(expiryInfo);
        return info;
    }

    /**
     * 获取列表
     */
    @Override
    public PageResult<WebMonSummaryInfo> queryList(SearchMonSummaryParam param, Integer platformid) {
        WebPlatformEntity entity = webPlatformDao.selectByPrimaryKey(platformid);
        Integer expiredmonths = entity.getExpiredmonths();
        //根据当前时间推算过期时间
        String startDate = DateUtils.dateformat(DateUtils.getFirstDateOfThisYear());
        String endDate = DateUtils.dateformat(DateUtils.getEndDateOfThisYear());
        String qtcompareDate = DateUtils.getfmCompareDate();//当前时间-20年
        String fmcompareDate = DateUtils.getqtCompareDate();//当前时间-10年
        Page<Object> page = PageHelper.startPage(param.getPageNumber(), param.getPageSize());
        List<WebMonSummaryInfo> infos = pacPatentinfoDao.queryList(
                param,
                platformid,
                startDate,//开始统计时间今年
                endDate,//结束统计时间今年,
                qtcompareDate,
                fmcompareDate,
                expiredmonths);
//       List<T> items, int pageNumber, int pageSize, int totalItemsCount
        Long total = page.getTotal();
        //查出所有的权力人类别
        List<CfgDictionaryInfo> dictionaryInfos = cfgDictionaryService.getNameAndValueByCode("1004");
        Map<String, String> map = new HashMap();
        for (CfgDictionaryInfo info : dictionaryInfos) {
            map.put(info.getValue(), info.getName());
        }
        for (WebMonSummaryInfo info : infos) {
            if (info.getTypeLevel1() != null)
                info.setType(map.get(info.getTypeLevel1().toString()));
        }

        PageResult<WebMonSummaryInfo> pagerUtils = new PageResult<WebMonSummaryInfo>(infos, param.getPageNumber(), param.getPageSize(), total.intValue());
        return pagerUtils;
    }

    /**
     * 获取区域转入数据
     */
    @Override
    public List<WebMonAnalysisInfo> getInList(Integer platformid, String order, String sort) {
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        //查询平台区域
        List<WebMonAnalysisInfo> infos = pacPatentinfoDao.getAnalysisByArea(startDate, endDate, platformid, order, sort);
        WebMonAnalysisInfo suminfo = new WebMonAnalysisInfo();
        suminfo.setWgsjcount(0);
        suminfo.setSyxxcount(0);
        suminfo.setFmcount(0);
        suminfo.setAreaName("全区");
        suminfo.setTotal(0);
        for (WebMonAnalysisInfo info : infos) {
            suminfo.setFmcount(suminfo.getFmcount() + info.getFmcount());
            suminfo.setSyxxcount(suminfo.getSyxxcount() + info.getSyxxcount());
            suminfo.setWgsjcount(suminfo.getWgsjcount() + info.getWgsjcount());
            suminfo.setTotal(suminfo.getTotal() + info.getTotal());
        }
        infos.add(0, suminfo);
        return infos;
    }

    @Override
    public List<WebMonAnalysisInfo> geOutList(Integer platformid, String order, String sort) {
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        //查询平台区域
        List<WebMonAnalysisInfo> infos = pacPatentinfoDao.getOutAnalysisByArea(startDate, endDate, platformid, order, sort);
        WebMonAnalysisInfo suminfo = new WebMonAnalysisInfo();
        suminfo.setWgsjcount(0);
        suminfo.setSyxxcount(0);
        suminfo.setFmcount(0);
        suminfo.setAreaName("全区");
        suminfo.setTotal(0);
        for (WebMonAnalysisInfo info : infos) {
            suminfo.setFmcount(suminfo.getFmcount() + info.getFmcount());
            suminfo.setSyxxcount(suminfo.getSyxxcount() + info.getSyxxcount());
            suminfo.setWgsjcount(suminfo.getWgsjcount() + info.getWgsjcount());
            suminfo.setTotal(suminfo.getTotal() + info.getTotal());
        }
        infos.add(0, suminfo);
        return infos;
    }

    @Override
    public List<WebMonInvalidAnalysisInfo> geInvalidList(Integer platformid, String order, String sort) {
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        List<WebMonInvalidAnalysisInfo> infos = pacPatentinfoDao.geInvalidList(startDate, endDate, platformid, order, sort);
        WebMonInvalidAnalysisInfo suminfo = new WebMonInvalidAnalysisInfo();
        suminfo.setWgsjcount(0);
        suminfo.setSyxxcount(0);
        suminfo.setFmcount(0);
        suminfo.setReason("全部");
        suminfo.setTotal(0);
        for (WebMonInvalidAnalysisInfo info : infos) {
            suminfo.setFmcount(suminfo.getFmcount() + info.getFmcount());
            suminfo.setSyxxcount(suminfo.getSyxxcount() + info.getSyxxcount());
            suminfo.setWgsjcount(suminfo.getWgsjcount() + info.getWgsjcount());
            suminfo.setTotal(suminfo.getTotal() + info.getTotal());
        }
        infos.add(0, suminfo);
        return infos;
    }

    @Override
    public PageResult<WebExpiryNoticeInfo> getExpiryNoticeList(Integer platformid, SearchExpiryNoticeParam param) {
        if (param.getPatType() != null && param.getPatType().size() > 0) {
            if (param.getPatType().contains(1)) param.getPatType().add(8);
            if (param.getPatType().contains(2)) param.getPatType().add(9);
        }
        Map<String, String> patTypeMap = cfgDictionaryService.getPatTypeMap();
        //获取平台信息
        WebPlatformEntity platformEntity = webPlatformDao.selectByPrimaryKey(platformid);
        //获取过期时间
        Integer expiredmonths = platformEntity.getExpiredmonths();
        //开始时间，结束时间
        if (expiredmonths == null) expiredmonths = 0;
        Date startDate = new Date();
        Date endDate = DateUtils.getDateByMonth(expiredmonths);
        Page<Object> page = PageHelper.startPage(param.getPageNumber(), param.getPageSize());
        List<WebExpiryNoticeInfo> infos = pacPatentinfoDao.getExpiryNoticeList(platformid, param, startDate, endDate);
        for (WebExpiryNoticeInfo info : infos) {
            info.setPatType(patTypeMap.get(info.getPatTypeName()));
        }
        Long total = page.getTotal();
        PageResult<WebExpiryNoticeInfo> result = new PageResult<WebExpiryNoticeInfo>(infos, param.getPageNumber(), param.getPageSize(), total.intValue());
        return result;
    }

    /**
     * 获取专利权转入信息
     */
    @Override
    public PageResult<WebApplyChangeInfo> getApplyChangeInList(Integer platformid, SearchExpiryNoticeParam param) {
        if (param.getPatType() != null && param.getPatType().size() > 0) {
            if (param.getPatType().contains(1)) param.getPatType().add(8);
            if (param.getPatType().contains(2)) param.getPatType().add(9);
        }
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        if (StringUtils.isNotBlank(param.getStartDate())) {
            startDate = DateUtils.parse(param.getStartDate());
        }
        if (StringUtils.isNotBlank(param.getEndDate())) {
            endDate = DateUtils.parse(param.getEndDate());
        }
        Page<Object> page = PageHelper.startPage(param.getPageNumber(), param.getPageSize());
        List<WebApplyChangeInfo> infos = pacPatentinfoDao.getApplyChangeInList(platformid, param, startDate, endDate);
        Long total = page.getTotal();
        PageResult<WebApplyChangeInfo> result = new PageResult<>(infos, param.getPageNumber(), param.getPageSize(), total.intValue());
        return result;
    }

    @Override
    public PageResult<WebApplyChangeInfo> getApplyChangeOutList(Integer platformid, SearchExpiryNoticeParam param) {
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        if (StringUtils.isNotBlank(param.getStartDate())) {
            startDate = DateUtils.parse(param.getStartDate());
        }
        if (StringUtils.isNotBlank(param.getEndDate())) {
            endDate = DateUtils.parse(param.getEndDate());
        }
        Page<Object> page = PageHelper.startPage(param.getPageNumber(), param.getPageSize());
        List<WebApplyChangeInfo> infos = pacPatentinfoDao.getApplyChangeOutList(platformid, param, startDate, endDate);
        Long total = page.getTotal();
        PageResult<WebApplyChangeInfo> result = new PageResult<WebApplyChangeInfo>(infos, param.getPageNumber(), param.getPageSize(), total.intValue());
        return result;
    }

    /**
     * 获取失效分析
     */
    @Override
    public PageResult<WebInvalidAnalysisInfo> getInvalidAnalysisList(Integer platformid, SearchExpiryNoticeParam param) {
        if (param.getPatType() != null && param.getPatType().size() > 0) {
            if (param.getPatType().contains(1)) param.getPatType().add(8);
            if (param.getPatType().contains(2)) param.getPatType().add(9);
        }
        Date startDate = DateUtils.getFirstDateOfThisYear();
        Date endDate = DateUtils.getEndDateOfThisYear();
        if (StringUtils.isNotBlank(param.getStartDate())) {
            startDate = DateUtils.parse(param.getStartDate());
        }
        if (StringUtils.isNotBlank(param.getEndDate())) {
            endDate = DateUtils.parse(param.getEndDate());
        }
        Page<Object> page = PageHelper.startPage(param.getPageNumber(), param.getPageSize());
        List<WebInvalidAnalysisInfo> infos = pacPatentinfoDao.getInvalidAnalysisList(platformid, param, startDate, endDate);
        //获取专利类型
        Map<String, String> patTypeMap = cfgDictionaryService.getPatTypeMap();
        for (WebInvalidAnalysisInfo info : infos) {
            if (StringUtils.isNotBlank(info.getPatType()))
                info.setPatTypeName(patTypeMap.get(info.getPatType()));
            //计算维持时间
            if (info.getExpiryDate() != null && info.getPatAppDate() != null)
                info.setMaintenanceYear(DateUtils.getMaintenanceYear(info.getExpiryDate(), info.getPatAppDate()));
        }
        Long total = page.getTotal();
        PageResult<WebInvalidAnalysisInfo> result = new PageResult<>(infos, param.getPageNumber(), param.getPageSize(), total.intValue());
        return result;
    }

    private Example getExampleByParam(SearchPatentParam param, Integer platformId) {
        Example example = new Example(PacPatentinfoEntity.class);
        Example.Criteria criteria = example.createCriteria();
        if (param.getAreaId() != null)
            criteria.andEqualTo("areaid", param.getAreaId());
        if (param.getPatType() != null)
            criteria.andIn("pattypename", param.getPatType());
        if (param.getPatHubTypeName() != null && param.getPatHubTypeName().isEmpty() == false) {
            criteria.andIn("pathubtypename", param.getPatHubTypeName());
        }
        if (param.getLawState() != null)
            criteria.andIn("lawstate", param.getLawState());
        if (StringUtils.isNotBlank(param.getPatNum()))
            criteria.andLike("patnum", "%" + param.getPatNum() + "%");
        if (StringUtils.isNotBlank(param.getPatName()))
            criteria.andLike("patname", "%" + param.getPatName() + "%");
        if (StringUtils.isNotBlank(param.getApplyPerson()))
            criteria.andLike("applyperson", "%" + param.getApplyPerson() + "%");
        if (StringUtils.isNotBlank(param.getInventPerson()))
            criteria.andLike("inventperson", "%" + param.getInventPerson() + "%");
        if (StringUtils.isNotBlank(param.getAgencyName()))
            criteria.andLike("agencyname", "%" + param.getAgencyName() + "%");
        if (StringUtils.isNotBlank(param.getAddress()))
            criteria.andLike("pataddresslast", "%" + param.getAddress() + "%");
        //申请日
        if (StringUtils.isNotBlank(param.getShenqingriStart()))
            criteria.andGreaterThanOrEqualTo("patappdate", param.getShenqingriStart());
        if (StringUtils.isNotBlank(param.getShenqingriEnd()))
            criteria.andLessThanOrEqualTo("patappdate", param.getShenqingriEnd());
        //实审日
        if (StringUtils.isNotBlank(param.getSsrStart()))
            criteria.andGreaterThanOrEqualTo("patsubexamdate", param.getSsrStart());
        if (StringUtils.isNotBlank(param.getSsrEnd()))
            criteria.andLessThanOrEqualTo("patsubexamdate", param.getSsrEnd());
        //授权日
        if (StringUtils.isNotBlank(param.getShouquanriStart()))
            criteria.andGreaterThanOrEqualTo("patapprovedate", param.getShouquanriStart());
        if (StringUtils.isNotBlank(param.getShouquanriEnd()))
            criteria.andLessThanOrEqualTo("patapprovedate", param.getShouquanriEnd());
        //公开日
        if (StringUtils.isNotBlank(param.getGkrStart()))
            criteria.andGreaterThanOrEqualTo("publicationdate", param.getGkrStart());
        if (StringUtils.isNotBlank(param.getGkrEnd()))
            criteria.andLessThanOrEqualTo("publicationdate", param.getGkrEnd());
        //失效日
        if (StringUtils.isNotBlank(param.getSxrStart()))
            criteria.andGreaterThanOrEqualTo("expirydate", param.getSxrStart());
        if (StringUtils.isNotBlank(param.getSxrEnd()))
            criteria.andLessThanOrEqualTo("expirydate", param.getSxrEnd());
        criteria.andEqualTo("platformid", platformId);
        String order = " patappdate";
        if (StringUtils.isNotBlank(param.getOrderby())) {
            order = " " + param.getOrderby();
        }
        if (StringUtils.isNotBlank(param.getSort())) {
            order += " " + param.getSort();
        } else {
            order += " desc";
        }
        example.setOrderByClause(order);
        return example;
    }


    /**
     * 检查必填以及数据格式
     */
    private CheckResult checkExcelData(HSSFWorkbook hssfWorkbook) {
        HSSFSheet sheet = hssfWorkbook.getSheet("Sheet1");
        if (sheet == null)
            return new CheckResult("无法找到Sheet1");
        HSSFRow row = null;
        //得到总行数，总列数
        int rowNum = sheet.getLastRowNum();
        if (rowNum == 0) {
            return new CheckResult("无数据");
        }
        for (int i = 1; i <= rowNum; i++) {
            row = sheet.getRow(i);
            Iterator<Integer> iterator = checkColumn.iterator();
            while (iterator.hasNext()) {
                Integer column = iterator.next();
                HSSFCell cell0 = row.getCell(column);
                //判断各个单元格是否为空
                CheckResult checkResult = checkRowError(cell0, i, column);
                if (!checkResult.isSuccess) {
                    return checkResult;
                }

            }
        }
        return new CheckResult(true);
    }

    /**
     * 判断某行某列有问题
     */
    private CheckResult checkRowError(HSSFCell cell, int rowNum, int cell_num) {
        //判断各个单元格是否为空
        if (cell == null || cell.equals("") || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
            return new CheckResult("出错啦！请检查第" + (rowNum + 1) + "行第" + (cell_num + 1) + "列。" + "必填！");
        }
        return new CheckResult(true);
    }

}
